<?php
// Get the day names
$days = App_Calendar::days(2);
// Previous and next month timestamps
$next = mktime(0, 0, 0, $this->month + 1, 1, $this->year);
$prev = mktime(0, 0, 0, $this->month - 1, 1, $this->year);
// Import the GET query array locally and remove the day
$qs = $_GET;
unset($qs['day']);
// Previous and next month query URIs
$prev = App::front()->getRequest()->getBaseUrl() . '?' . http_build_query(array_merge($qs, array('month' => date('n', $prev), 'year' => date('Y', $prev))));
$next = App::front()->getRequest()->getBaseUrl() . '?' . http_build_query(array_merge($qs, array('month' => date('n', $next), 'year' => date('Y', $next))));

?>
<table class="app_calendar">
	<tr class="controls">
		<td class="prev"><?php echo Vendor_Helper_Html::anchor($prev, '&laquo;') ?></td>
		<td class="title" colspan="5"><?php echo strftime('%B %Y', mktime(0, 0, 0, $this->month, 1, $this->year)) ?></td>
		<td class="next"><?php echo Vendor\Helper\Html::anchor($next, '&raquo;') ?></td>
	</tr>
	<tr>
	<?php foreach ($days as $day): ?>
		<th><?php echo $day ?></th>
		<?php endforeach ?>
	</tr>
	<?php foreach ($this->weeks as $week): ?>
	<tr>
	<?php foreach ($week as $day):

	list ($number, $current, $data) = $day;

	if (is_array($data)) {
	    $classes = $data['classes'];
	    $output = empty($data['output']) ? '' : '<ul class="output"><li>' . implode('</li><li>', $data['output']) . '</li></ul>';
	}else {
	    $classes = array();
	    $output = '';
	}

	?>
		<td class="<?php echo implode(' ', $classes) ?>"><span class="day"><?php echo $day[0] ?></span><?php echo $output ?></td>
		<?php endforeach ?>
	</tr>
	<?php endforeach ?>
</table>
